Change Look At Target  

By Hubert Ronald / Leave a response / May 28, 2018

When have many objects on 3D, it's useful select them, when mouse down on them.

This snippet was orginally taken from Help understand Click to View Object Script

using UnityEngine;
using System.Collections;

public class ChangeLookAtTarget : MonoBehaviour {

    public GameObject target; // the target that the camera should look at

    void Start() {
        if (target == null) 
        {
            target = this.gameObject;
            Debug.Log ("ChangeLookAtTarget target not specified. Defaulting to parent GameObject");
        }
    }

    // Called when MouseDown on this gameObject
    void OnMouseDown () {
        // change the target of the LookAtTarget script to be this gameobject.
        LookAtTarget.target = target;
        Camera.main.fieldOfView = 60*target.transform.localScale.x;
    }
}





Hubert Ronald

Hiya. I'm Ronald, an Industrial Engineer from Colombia. Hope you enjoyed my ad-free, bullshit-free site. If you liked it, tell someone about it.

Write a response

Your email address will not be published.

RECENT NEWS

Gradient is a small library which offers a clean, minimalistic but powerful API for gradients on mesh canvas when you use it on Gideros Mobile. This script take colors from uiGradients like inspiration.

More information about before here.

SUBSCRIBE

Get monthly updates and free resources.


CONNECT WITH ME